
/** 引入axios 对象 */
import axios from "axios";

/**
 * 定义一个Ajax
 * @param {AxiosRequestConfig} requst 需要传递的参数
 */
const baseURL = "http://10.55.15.14:8301/";
//  const baseURL= "http://10.55.15.29:8301/";

const Ajax = async request => {
  const token = localStorage.getItem('ACCESS_TOKEN')
  let param = {
    // baseURL: '/apis',
    url: baseURL + request.url,
    params: request.params || {},
    query: request.query || {},
    data: request.data || {},
    id: request.id || '',
    method: request.method ? request.method : 'GET',
    // headers: {'Content-Type': 'application/json;charset=Utf-8'},
    headers: { 'Authorization': `bearer ${token}` },
    // headers: {'Authorization': `bearer 73921d5e-ba87-420b-8054-7818bc72745d`},
    timeout: 15000
  };

  let result = await axios(param).catch(e => {
    return { code: 900, message: 'local error' };
  });
  if (result) return result.data;
}

/** 导出Ajax 方法 */
export default Ajax;